package com.uestc.admin;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.uestc.coprocessor.MultiColumnAggregateClient;
import com.uestc.hbase.MTable;
import com.uestc.util.Log;

public class FileAdmin implements AdminBase {

	private String columnName = "FileColumns";
	private String tableName = "file";

	@Override
	public String getInfo(int page, int limit, HttpServletRequest request) throws Throwable {
		return this.getDetailInfo(tableName, columnName, Arrays.asList(new String[] { "info" }), page, limit, request);
	}

	@Override
	public String getColumnName() {
		return columnName;
	}

	@Override
	public String getTableName() {
		return tableName;
	}

	@Override
	public String getInfoWithCondition(int page, int limit, HashMap<String, String> conditions,
			HttpServletRequest request) throws Throwable {
		return this.getDetailInfo(tableName, this.columnName, Arrays.asList(new String[] { "info" }), page, limit,
				request, "info", conditions, MTable.FILTER_TYPE.PREFIX_FILTER);
	}

	/**
	 * 这里是用来统计各个云上存储的文件总量bit
	 * 
	 * @return
	 * @throws IOException
	 */
	public MultiColumnAggregateClient.CountInfo sumUpSizes() throws IOException {
		MultiColumnAggregateClient client = new MultiColumnAggregateClient();
		MultiColumnAggregateClient.CountInfo info = null;
		MTable mTable = null;
		try {
			mTable = new MTable(tableName);
			info = client.getSeveralCounts(mTable.getTable(), "Qiniu;Qiniu2;Jinshan");
		} catch (Throwable e) {
			Log.logException(e);
		} finally {
			if (mTable != null)
				mTable.close();
		}
		return info;
	}

	@Override
	public String getDateColumnName() {
		return "uploadTime";
	}
}
